package org.fireking.myapplication.drawing

import android.graphics.Canvas
import android.graphics.Paint
import com.github.mikephil.charting.utils.Transformer
import org.fireking.myapplication.ChartDrawingRenderer

/**
 * 基于策略模式的图形基类
 */
class Shape(
    val drawingStrategy: ShapeDrawingStrategy,
    val color: Int,
    val lineWidth: Float
) {
    // 是否被选中
    var isSelected: Boolean = false

    // 检查点是否在图形上或附近（用于选择）
    fun containsPoint(x: Float, y: Float, touchTolerance: Float = 20f): Boolean {
        return drawingStrategy.containsPoint(x, y, touchTolerance)
    }

    // 获取控制点
    fun getControlPoints(): List<ChartDrawingRenderer.ControlPoint> {
        return drawingStrategy.getControlPoints()
    }

    // 应用控制点的移动
    fun applyControlPointMove(controlPointId: Int, deltaX: Float, deltaY: Float) {
        drawingStrategy.applyControlPointMove(controlPointId, deltaX, deltaY)
    }

    // 绘制图形
    fun draw(canvas: Canvas, transformer: Transformer?, paint: Paint) {
        drawingStrategy.draw(canvas, transformer, paint)
    }

    // 移动整个图形
    fun move(deltaX: Float, deltaY: Float) {
        drawingStrategy.move(deltaX, deltaY)
    }
}